import "package:flutter/material.dart";
import "../widget/tabBottomBar.dart";
import "../widget/tabBottomBarItem.dart";
import "./home.dart"; //首页
import "./dynamic.dart";
import "./own.dart";
import "./shop.dart";
import "./publish.dart";

class AppTabBottomBar extends StatefulWidget {
  const AppTabBottomBar({super.key});
  @override
  State<StatefulWidget> createState() {
    return _AppTabBottomBarState();
  }
}

class _AppTabBottomBarState extends State<AppTabBottomBar> {
  int currentIndex = 0;
  List<Widget> pages = [
    const SwHomePage(),
    const SwDynamicPage(),
    const Publish(),
    const Shop(),
    const SwOwnPage(),
  ];
  late PageController pageController;
  @override
  void initState() {
    pageController = PageController(initialPage: currentIndex);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          PageView(
            controller: pageController,
            physics: const NeverScrollableScrollPhysics(), //阻止通过滑动切换
            children: pages,
          ),
          Positioned(
            bottom: 0,
            left: 0,
            right: 0,
            child: TabBottomBar(
              initIndex: currentIndex,
              height: 40,
              color: const Color.fromARGB(232, 255, 255, 255),
              backgroundImageUrl: "./images/1.jpg",
              backgroundImageOpacity: 0.2,
              selectLabelColor: const Color.fromARGB(255, 216, 140, 231),
              selectedIconColor: const Color.fromARGB(255, 216, 140, 231),
              iconSize: 16,
              selectedIconSize: 16,
              labelFontSize: 10,
              selectedLabelFontSize: 10,
              onChange: (value) {
                setState(() {
                  currentIndex = value;
                  pageController.jumpToPage(value);
                });
              },
              items: [
                TabBottomBarItem(
                  iconName: Icons.home,
                  imageUrl: "./images/tab_1.jpg",
                  selectedImageUrl: "./images/tab_1.jpg",
                  label: "首页",
                ),
                TabBottomBarItem(
                  iconName: Icons.recommend_outlined,
                  imageUrl: "./images/tab_2.jpg",
                  selectedImageUrl: "./images/tab_2.jpg",
                  label: "动态",
                ),
                TabBottomBarItem(
                  iconName: Icons.add,
                  imageUrl: "./images/tab_5.jpg",
                  selectedImageUrl: "./images/tab_5.jpg",
                  label: "新增",
                ),
                TabBottomBarItem(
                  iconName: Icons.shopping_bag,
                  imageUrl: "./images/tab_3.jpg",
                  selectedImageUrl: "./images/tab_3.jpg",
                  label: "会员购",
                ),
                TabBottomBarItem(
                  iconName: Icons.supervised_user_circle,
                  imageUrl: "./images/tab_4.jpg",
                  selectedImageUrl: "./images/tab_4.jpg",
                  label: "我的",
                )
              ],
            ), //底部导航栏
          )
        ],
      ),
    );
  }
}
